package com.example.ch03.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ch03.service.UserService;
import com.example.ch03.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/getCount")
    public String getCount(){
        System.out.println("一共"+userService.count()+"条数据");
        return "一共"+userService.count()+"条数据";
    }

    @RequestMapping("/getList")
    public String getList(String userName){


//        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<SysUser>();
//        queryWrapper.eq(SysUser::getRealname,userName);
//        queryWrapper.like(SysUser::getRealname,userName);
//        List<SysUser> userList = userService.list(queryWrapper);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("realname","2");
        Page<SysUser> page = new Page<SysUser>(1,2);
        IPage<SysUser> userList = userService.page(page);

        return JSON.toJSONString(userList);
    }
}
